package com.tourManagement.controller;

import com.tourManagement.entity.RT;
import com.tourManagement.entity.User;
import com.tourManagement.service.UserService;
import lombok.AllArgsConstructor;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.sql.SQLException;

/**
 * Author:grass
 * Date:2022/10/16 0016
 */
@RestController
@AllArgsConstructor
@RequestMapping("/userManage")
public class UserManage {
    private UserService userService;//创建服务对象
    //添加(注册)用户
    @GetMapping("/registerUser")
    public RT registerUser(User user) throws SQLException{
        return RT.success(userService.insert(user));
    }

    //修改用户信息
    @GetMapping("/update")
    public RT updateUser(User user) throws SQLException{
        return RT.success(userService.update(user));
    }

    //删除用户
    @GetMapping("/deleteUser")
    public RT deleteUser(User user) throws SQLException{
        return RT.success(userService.delete(user));
    }


    //查询指定用户
    @GetMapping("/selectByKey")
    public RT selectByKey(User user) throws SQLException{
        return RT.success(userService.selectByKey(user));
    }


    //查询所有用户
    @GetMapping("/select")
    public RT select() throws SQLException{
        return RT.success(userService.select());
    }

}
